package com.ruoyi.controller.pay;

import cn.hutool.core.date.DateUtil;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.LiveStatus;
import com.ruoyi.common.enums.RuleType;
import com.ruoyi.common.enums.pay.TimeUnit;
import com.ruoyi.system.domain.SysChannel;
import com.ruoyi.system.domain.SysControl;
import com.ruoyi.system.domain.SysOrder;
import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.service.ISysChannelService;
import com.ruoyi.system.service.ISysOrderService;
import com.ruoyi.system.service.ISysPayService;
import com.ruoyi.system.service.ISysUserChannelService;
import com.ruoyi.system.vo.SysControlRes;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.thymeleaf.util.ListUtils;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 支付Controller
 *
 * @author Ericcc
 * @date 2021-02-12
 */
@Controller
@RequestMapping("/pay")
public class PayController extends BaseController {

    @Autowired
    private ISysUserChannelService sysUserChannelService;

    @Autowired
    private ISysChannelService sysChannelService;

    @Autowired
    private ISysOrderService sysOrderService;

    @Autowired
    private ISysPayService sysPayService;

    private String prefix = "pay";

    private int testUser = 10000;

    @GetMapping("/getTime")
    @ResponseBody
    public String getTime(ModelMap mmap)
    {
        return new Date().toString();
    }

    @GetMapping("/India")
    public String India(ModelMap mmap)
    {
        List<SysChannel> sysChannels = sysChannelService.selectUserSysChannel();
        mmap.put("sysChannels",sysChannels);
        return prefix + "/pay";
    }

    @PostMapping("/India/testOrder")
    @ResponseBody
    @Log(title = "测试订单", businessType = BusinessType.PAYREQ)
    public String testOrder(SysOrder sysOrder)
    {
        return sysOrderService.insertSysOrder(sysOrder);
    }

    @GetMapping("/getLink/{orderid}")
    public String getLink(@PathVariable("orderid") long orderid,ModelMap modelMap) throws Exception {
        System.out.println("收到了"+orderid);
        modelMap.put("jsonStr",sysPayService.getLink(orderid));
        return prefix + "/checkstand";
    }

}
